<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-search"
          size="mini"
          @click="handleSearch"
          >搜索</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['device:moldChange:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['device:moldChange:delete']"
        >
          删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['device:moldChange:export']"
        >
          导出
        </el-button>
      </el-col>
      <!-- 分页效果 -->
      <el-col :span="2.2" style="position: absolute; right: 0px; top: 0">
        <Page
          style="margin-right: 0px"
          :current="queryParams.pageNum"
          :page-size="queryParams.pageSize"
          :total="total"
          @on-change="pageChange"
          simple
        ></Page>
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      highlight-current-row
      border
      stripe
      v-loading="loading"
      height="calc(100% - 350px)"
      :data="moldChangeList"
      @selection-change="handleSelectionChange"
      @row-click="handleOpen"
      :header-cell-style="{ 'text-align': 'center' }"
    >
      <el-table-column
        label="#"
        type="index"
        fixed="left"
        width="40"
        align="center"
      />
      <el-table-column
        type="selection"
        fixed="left"
        width="55"
        align="center"
      />
      <el-table-column
        label="单据编号"
        :show-overflow-tooltip="true"
        width="115"
        align="center"
        prop="moldBillCode"
      />
      <!--      <el-table-column label="模具编号" :show-overflow-tooltip="true" width="200" align="center" prop="moldCode" />
      <el-table-column label="模具名称" :show-overflow-tooltip="true" align="center" prop="moldName" />
      <el-table-column label="模具尺寸" :show-overflow-tooltip="true" width="100" align="center" prop="moldSize" />
      <el-table-column label="模具吨位" :show-overflow-tooltip="true" width="80" align="center" prop="moldTon" />
      <el-table-column label="调出原因" :show-overflow-tooltip="true" width="80" align="center" prop="moldReason">
        <template v-slot="scope">
          <dict-tag :options="moldReasonOptions" :value="scope.row.moldReason" />
        </template>
      </el-table-column>-->
      <el-table-column
        label="原因描述"
        :show-overflow-tooltip="true"
        align="center"
        prop="moldDescribe"
      />
      <!--      <el-table-column label="调出地点" :show-overflow-tooltip="true" align="center" prop="moldPlace" />-->
      <el-table-column
        label="单据状态"
        :show-overflow-tooltip="true"
        align="center"
        prop="moldState"
      >
        <template v-slot="scope">
          <dict-tag :options="moldStateOptions" :value="scope.row.moldState" />
        </template>
      </el-table-column>
      <el-table-column
        label="创建人员"
        :show-overflow-tooltip="true"
        width="80"
        align="center"
        prop="moldCreateBy"
      />
      <el-table-column
        label="创建时间"
        :show-overflow-tooltip="true"
        width="130"
        align="center"
        prop="moldCreateTime"
      />
      <el-table-column
        label="更新人员"
        :show-overflow-tooltip="true"
        width="80"
        align="center"
        prop="moldUpdateBy"
      />
      <el-table-column
        label="更新时间"
        :show-overflow-tooltip="true"
        width="130"
        align="center"
        prop="moldUpdateTime"
      />
      <el-table-column
        label="操作"
        align="center"
        width="250"
        fixed="right"
        class-name="small-padding fixed-width"
      >
        <template #default="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-circle-check"
            @click="handleUpdate(scope.row)"
            v-show="scope.row.moldState === 1"
            v-hasPermi="['device:moldChange:confirmOne']"
          >
            模具管理员确认
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-circle-check"
            @click="handleUpdate(scope.row)"
            v-show="scope.row.moldState === 2"
            v-hasPermi="['device:moldChange:confirmTwo']"
          >
            计划员确认
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-upload"
            v-show="!(scope.row.moldState === 1)"
            @click="handleSelectionChangeChild(scope.row)"
            v-hasPermi="['device:moldChange:upload']"
          >
            上传照片
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-s-release"
            @click="handleRevoke(scope.row)"
            v-show="scope.row.moldState === 2 || scope.row.moldState === 8"
            v-hasPermi="['device:moldChange:confirmRevoke']"
          >
            撤回
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 下左表 -->
    <el-table
      highlight-current-row
      border
      stripe
      height="300px"
      :data="moldRowList"
      :header-cell-style="{ 'text-align': 'center' }"
      style="overflow: auto; width: 49%; float: left"
    >
      <el-table-column label="#" type="index" width="40" align="center" />
      <el-table-column
        label="模具编号"
        :show-overflow-tooltip="true"
        align="center"
        prop="mjmMjbh"
      />
      <el-table-column
        label="模具名称"
        :show-overflow-tooltip="true"
        align="center"
        prop="mjmMjmc"
      />
      <el-table-column
        label="模具规格"
        :show-overflow-tooltip="true"
        width="150"
        align="center"
        prop="mjmMjgg"
      />
      <el-table-column
        label="模具吨位"
        :show-overflow-tooltip="true"
        width="80"
        align="center"
        prop="mjmDw"
      />
    </el-table>

    <!-- 下右图 -->
    <el-carousel
      trigger="click"
      height="300px"
      :autoplay="false"
      arrow="always"
      style="width: 49%; text-align: center; float: right"
    >
      <el-carousel-item v-for="item in imgList" :key="item">
        <el-image :src="item" fit="contain" :preview-src-list="imgList">
        </el-image>
      </el-carousel-item>
    </el-carousel>

    <!-- 查询对话框   -->
    <el-dialog
      :title="title"
      v-model="openSearch"
      :close-on-click-modal="false"
      draggable
      width="680px"
      append-to-body
    >
      <el-form
        :model="queryParams"
        ref="queryForm"
        :inline="true"
        v-show="showSearch"
        label-width="68px"
      >
        <el-col :span="12">
          <el-form-item label="开单日期">
            <el-date-picker
              v-model="dateRange"
              size="small"
              style="width: 215px"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="单据编号" prop="moldBillCode">
            <el-input
              v-model="queryParams.moldBillCode"
              placeholder="请输入单据编号"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="模具编号" prop="moldCode">
            <el-input
              v-model="queryParams.moldCode"
              placeholder="请输入模具编号"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="模具名称" prop="moldName">
            <el-input
              v-model="queryParams.moldName"
              placeholder="请输入模具名称"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <!--        <el-col :span="24">
          <el-form-item label="调出原因" prop="moldReason">
            <el-select v-model="queryParams.moldReason" placeholder="请选择调出原因" clearable size="small">
              <el-option v-for="item in moldReasonOptions" :key="item.dictValue" :label="item.dictLabel" :value="item.dictValue" />
            </el-select>
          </el-form-item>
        </el-col>-->
        <el-col :span="24">
          <el-form-item label="单据状态" prop="moldReason">
            <el-select
              style="width: 535px"
              v-model="queryParams.moldState"
              placeholder="请选择单据状态"
              clearable
              size="small"
            >
              <el-option
                v-for="item in moldStateOptions"
                :key="item.dictValue"
                :label="item.dictLabel"
                :value="item.dictValue"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item
            style="margin-top: 25px; display: flex; justify-content: flex-end"
          >
            <el-button @click="cancel">取消</el-button>
            <el-button type="primary" @click="handleQuery">确认</el-button>
          </el-form-item>
        </el-col>
      </el-form>
    </el-dialog>

    <!-- 添加模具对话框 -->
    <el-dialog
      :title="title"
      v-model="open"
      :close-on-click-modal="false"
      draggable
      width="800px"
      append-to-body
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-col :span="22">
          <el-form-item label="单据编号" prop="moldBillCode">
            <el-input
              disabled
              v-model="form.moldBillCode"
              placeholder="系统自动生成"
            />
          </el-form-item>
        </el-col>
        <el-col :span="1" style="margin-left: 10px">
          <el-button
            :disabled="confirmOneFlag && confirmTwoFlag"
            class="addButton"
            @click="clickAddButton"
            type="primary"
            icon="el-icon-plus"
            circle
          />
        </el-col>
        <!--        <el-col :span="12">
          <el-form-item label="调出原因" prop="moldReason">
            <el-select v-model="form.moldReason" placeholder="请选择调出原因" clearable :disabled="confirmOneFlag || confirmTwoFlag" size="small">
              <el-option v-for="item in moldReasonOptions" :key="item.dictValue" :label="item.dictLabel" :value="item.dictValue" />
            </el-select>
          </el-form-item>
        </el-col>-->
        <el-col :span="24">
          <el-table
            highlight-current-row
            border
            stripe
            :data="moldDetailList"
            :header-cell-style="{ 'text-align': 'center' }"
            style="overflow: auto"
            empty-text="每个单据只能添加10个模具"
          >
            <el-table-column label="#" type="index" width="40" align="center" />
            <el-table-column
              label="模具编号"
              :show-overflow-tooltip="true"
              width="204"
              align="center"
              prop="mjmMjbh"
            />
            <el-table-column
              label="模具名称"
              :show-overflow-tooltip="true"
              width="204"
              align="center"
              prop="mjmMjmc"
            />
            <el-table-column
              label="模具规格"
              :show-overflow-tooltip="true"
              width="150"
              align="center"
              prop="mjmMjgg"
            />
            <el-table-column
              label="模具吨位"
              :show-overflow-tooltip="true"
              width="80"
              align="center"
              prop="mjmDw"
            />
            <el-table-column
              label="操作"
              align="center"
              width="80"
              fixed="right"
              class-name="small-padding fixed-width"
            >
              <template v-slot="scope">
                <el-button
                  :disabled="confirmTwoFlag"
                  type="text"
                  size="mini"
                  @click="clickDelChild(scope.row)"
                >
                  删除
                </el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-col>
        <!--        <el-col :spa="24">
          <el-form-item label="调出地点" prop="moldPlace">
            <el-input :disabled="confirmOneFlag || confirmTwoFlag" v-model="form.moldPlace" placeholder="请输入调出地点" />
          </el-form-item>
        </el-col>-->
        <el-col :span="24">
          <el-form-item label="原因描述" prop="moldDescribe">
            <el-input
              :disabled="confirmOneFlag || confirmTwoFlag"
              type="textarea"
              v-model="form.moldDescribe"
              placeholder="请输入原因描述，此处为必填项"
            />
          </el-form-item>
        </el-col>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="submitForm">确 定</el-button>
      </div>
    </el-dialog>

    <!-- 添加模具维修作业对话框 -->
    <el-dialog
      :title="title"
      v-model="openChild"
      :close-on-click-modal="false"
      draggable
      width="650px"
      append-to-body
    >
      <el-form
        ref="queryForm"
        :model="queryParamsChild"
        v-show="showSearch"
        label-width="80px"
      >
        <el-form-item label="筛选条件">
          <el-input
            v-model="queryParamsChild.mjmMjmc"
            clearable
            size="small"
            @input="clickAddButton"
          />
        </el-form-item>
        <el-table
          highlight-current-row
          border
          stripe
          @scrollBottom="load"
          height="400"
          :data="ModelList"
          @selection-change="handleSelectionMold"
          :header-cell-style="{ 'text-align': 'center' }"
          style="overflow: auto"
        >
          <el-table-column label="#" type="index" width="40" align="center" />
          <el-table-column type="selection" width="55" align="center" />
          <el-table-column
            label="模具编号"
            :show-overflow-tooltip="true"
            align="center"
            prop="mjmMjbh"
          />
          <el-table-column
            label="模具名称"
            :show-overflow-tooltip="true"
            align="center"
            prop="mjmMjmc"
          />
          <el-table-column
            label="模具规格"
            :show-overflow-tooltip="true"
            width="150"
            align="center"
            prop="mjmMjgg"
          />
          <el-table-column
            label="模具吨位"
            :show-overflow-tooltip="true"
            width="80"
            align="center"
            prop="mjmDw"
          />
        </el-table>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="openChild = false">取 消</el-button>
        <el-button type="primary" @click="handleConfirmAdd">确 定</el-button>
      </div>
    </el-dialog>

    <el-dialog
      title="上传文件"
      v-model="openUpload"
      :close-on-click-modal="false"
      draggable
      width="400px"
      append-to-body
      @close="getList"
    >
      <el-upload
        class="upload-demo"
        drag
        action="#"
        multiple
        style="display: inline-block"
        :show-file-list="false"
        :http-request="handleUpload"
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip" slot="tip">只能上传jpg/png文件</div>
      </el-upload>
    </el-dialog>
  </div>
</template>

<script>
import {
  addMoldChange,
  approvalMoldChange,
  confirmMoldChange,
  delMoldChange,
  exportMoldChange,
  getMoldChange,
  listMoldChange,
  printMoldChange,
  processMoldChange,
  revokeMoldChange,
  uploadMoldChange,
} from "@/api/device/moldChange";
import { getMjmByBhOrMc } from "@/api/project/mjmMstr";

export default {
  name: "MoldChangePut",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 模具管理员确认标识符
      confirmOneFlag: false,
      // 计划员确认标识符
      confirmTwoFlag: false,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      moldBillCodes: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      openSearch: false,
      // 总条数
      total: 0,
      // 模具变动表格数据
      moldChangeList: [],
      // 所有模具
      ModelList: [],
      // 当前行图片预览
      imgList: [],
      // 当前行模具
      moldRowList: [],
      // 添加模具多选框数据
      moldDetailList: [],
      // 上传文件用表单
      selectionChildData: [],
      selectionAddData: [],
      // 开单日期时间范围
      dateRange: [
        this.$moment().add(-1, "month").startOf("month").toDate(),
        this.$moment().endOf("month").toDate(),
      ],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      openChild: false,
      openUpload: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: document.body.clientHeight > 900 ? 20 : 15,
        moldBillCode: null,
        moldCode: null,
        moldReason: null,
        moldOutPutFlag: 0,
        moldState: null,
      },
      queryParamsChild: {
        pageNum: 1,
        pageSize: 25,
        mjmMjmc: null,
      },
      // 模具变动原因
      moldReasonOptions: [],
      // 模具单状态
      moldStateOptions: [],
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        moldReason: [
          { required: true, message: "调出原因不能为空", trigger: "blur" },
        ],
        moldDescribe: [
          { required: true, message: "原因描述不能为空", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.getAllDicts("mold_change_state_put").then((response) => {
      this.moldStateOptions = response.data;
    });
    this.getAllDicts("mold_change_reason").then((response) => {
      this.moldReasonOptions = response.data;
    });
    this.getList();
  },
  methods: {
    /** 查询模具变动列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.dateRange && "" != this.dateRange) {
        this.queryParams.params["beginDate"] = this.moment(
          this.dateRange[0]
        ).format("YYYY-MM-DD HH:mm:ss");
        this.queryParams.params["endDate"] = this.moment(
          this.dateRange[1]
        ).format("YYYY-MM-DD HH:mm:ss");
      }
      this.imgList = [];
      this.moldRowList = [];
      listMoldChange(this.queryParams).then((response) => {
        this.moldChangeList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    //load
    load() {
      if (
        this.queryParamsChild.pageNum <
        Math.ceil(this.totalAdd / this.queryParamsChild.pageSize)
      ) {
        this.queryParamsChild.pageSize = 25;
        this.queryParamsChild.pageNum++;
        getMjmByBhOrMc(this.queryParamsChild).then((response) => {
          this.ModelList = this.ModelList.concat(response.rows);
          this.totalAdd = response.total;
        });
      }
      return 0;
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.openSearch = false;
      this.handleInvalid();
      this.reset();
    },
    // 添加框取消按钮
    cancelChild() {
      this.form.moldCode = null;
      this.form.moldName = null;
      this.form.moldSize = null;
      this.form.moldTon = null;
      this.openChild = false;
    },
    handleInvalid() {
      this.confirmOneFlag = false;
      this.confirmTwoFlag = false;
    },
    // 表单重置
    reset() {
      this.form = {
        moldId: null,
        moldBillCode: null,
        moldCode: null,
        moldName: null,
        moldSize: null,
        moldTon: null,
        moldReason: null,
        moldDescribe: null,
        moldPlace: null,
        moldOutPutFlag: 0,
        moldState: 1,
        moldCreateTime: null,
        moldCreateBy: null,
        moldUpdateTime: null,
        moldUpdateBy: null,
      };
      this.resetForm("form");
    },
    /** 添加模具确认 */
    handleConfirmAdd() {
      this.selectionAddData.forEach((item) => {
        this.moldDetailList.push(item);
      });
      this.openChild = false;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.moldChangeList = [];
      this.getList();
      this.openSearch = false;
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.moldId);
      this.moldBillCodes = selection.map((item) => item.moldBillCode);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增界面多选框事件 */
    handleSelectionChangeChild(selection) {
      this.selectionChildData = selection;
      this.openUpload = true;
    },
    /** 表格点击事件 */
    handleSelectionMold(selection) {
      this.selectionAddData = selection;
      /*this.form.moldCode = row.mjmMjbh
      this.form.moldName = row.mjmMjmc
      this.form.moldSize = row.mjmMjgg
      this.form.moldTon = row.mjmDw*/
    },
    /** 添加界面点击加号事件 */
    clickAddButton() {
      this.queryParamsChild.pageNum = 1;
      this.queryParamsChild.pageSize = 25;
      getMjmByBhOrMc(this.queryParamsChild).then((res) => {
        this.ModelList = res.rows;
        this.totalAdd = res.total;
      });
      this.openChild = true;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.handleInvalid();
      this.moldDetailList = [];
      this.open = true;
      this.title = "添加模具入库";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.handleInvalid();
      if (row.moldState === 1) {
        this.confirmOneFlag = true;
      } else if (row.moldState === 2) {
        this.confirmOneFlag = true;
        this.confirmTwoFlag = true;
      }
      this.reset();
      const moldId = row.moldId || this.ids;
      getMoldChange(moldId).then((response) => {
        this.form = response.data;
        this.moldDetailList = JSON.parse(response.data.moldDetail || "[]");
        this.open = true;
        this.title = "确认模具入库单";
      });
    },
    /** 审核模具 */
    handleProcess(row) {
      this.$confirm(
        '确认审批单号为"' + row.moldBillCode + '"的数据项?',
        "确认",
        {
          cancelButtonText: "取消",
          confirmButtonText: "确定",
          type: "warning",
        }
      )
        .then(function () {
          return processMoldChange(row);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("审批成功");
        })
        .catch(() => {});
    },
    /** 批准模具 */
    handleApproval(row) {
      this.$confirm(
        '确认批准单号为"' + row.moldBillCode + '"的数据项?',
        "确认",
        {
          cancelButtonText: "取消",
          confirmButtonText: "确定",
          type: "warning",
        }
      )
        .then(function () {
          return approvalMoldChange(row);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("批准成功");
        })
        .catch(() => {});
    },
    /** 打印单据后结案 */
    handlePrint(row) {
      this.$confirm(
        '确认打印单号为"' +
          row.moldBillCode +
          '"的单据，打印后本单据如未结案将结案?',
        "确认",
        {
          cancelButtonText: "取消",
          confirmButtonText: "确定",
          type: "warning",
        }
      )
        .then(function () {
          return printMoldChange(row);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("打印成功");
        })
        .catch(() => {});
    },
    /** 单据撤回 */
    handleRevoke(row) {
      this.$confirm(
        '确认撤回单号为"' + row.moldBillCode + '"的数据项?',
        "确认",
        {
          cancelButtonText: "取消",
          confirmButtonText: "确定",
          type: "warning",
        }
      )
        .then(function () {
          return revokeMoldChange(row);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("撤回成功");
        })
        .catch(() => {});
    },
    handleSearch() {
      this.reset();
      this.title = "查询模具入库单";
      this.openSearch = true;
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.moldDetailList.length > 10) {
            this.$message.error("请将该单据模具数量控制在10个以内！");
          } else {
            this.form.moldDetail = JSON.stringify(this.moldDetailList);
            this.form.moldCode = this.moldDetailList
              .map((o) => o.mjmMjbh)
              .join(",");
            this.form.moldName = this.moldDetailList
              .map((o) => o.mjmMjmc)
              .join(",");
            if (this.form.moldId != null) {
              if (this.form.moldDetail === null) {
                return this.$message.error("模具不能为空！");
              }
              confirmMoldChange(this.form).then((response) => {
                this.msgSuccess("确认成功");
                this.open = false;
                this.handleInvalid();
                this.getList();
              });
            } else {
              addMoldChange(this.form).then((response) => {
                this.msgSuccess("新增成功");
                this.open = false;
                this.reset();
                this.getList();
              });
            }
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const moldIds = row.moldId || this.ids;
      const moldBillCodes = row.moldBillCode || this.moldBillCodes;
      this.$confirm(
        '是否确认删除模具入库单编号为"' + moldBillCodes + '"的数据项?',
        "确认",
        {
          cancelButtonText: "取消",
          confirmButtonText: "确定",
          type: "warning",
        }
      )
        .then(function () {
          return delMoldChange(moldIds);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有模具入库单数据项?", "确认", {
        cancelButtonText: "取消",
        confirmButtonText: "确定",
        type: "warning",
      })
        .then(() => {
          this.exportLoading = true;
          return exportMoldChange(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
          this.exportLoading = false;
        })
        .catch(() => {});
    },
    /** 上传按钮操作 */
    handleUpload(fileList) {
      const reader = new FileReader();
      reader.readAsDataURL(fileList.file);
      reader.onload = () => {
        let formData = new FormData();

        formData.append("file", fileList.file);
        formData.append("moldBillCode", this.selectionChildData.moldBillCode);

        uploadMoldChange(formData).then((res) => {
          if (res.msg == "上传成功！") {
            this.$message.success(res.msg);
          } else {
            this.$message.error(res.msg);
            console.log(res);
          }
        });
      };
    },
    /** 查看按钮操作 */
    handleOpen(row) {
      this.imgList = [];
      this.moldRowList = JSON.parse(row.moldDetail);
      if (row.moldFilePath !== null && row.moldFilePath !== "") {
        this.imgList = JSON.parse(row.moldFilePath).map(
          (file) => process.env.VUE_APP_BASE_API + file
        );
      }
    },
    /** 点击删除子项 */
    clickDelChild(row) {
      this.moldDetailList = this.moldDetailList.filter((item) => item !== row);
    },
    pageChange(page) {
      this.queryParams.pageNum = page;
      this.getList();
    },
  },
};
</script>

<style lang="scss" scoped></style>
